use wasm_bindgen::prelude::*;
use wee_alloc::WeeAlloc;

#[global_allocator]
static ALLOC: WeeAlloc = WeeAlloc::INIT;

// 调用浏览器的内置API函数
#[wasm_bindgen]
extern "C" {
  fn alert(s: &str);
  fn confirm(s: &str) -> bool;
  #[wasm_bindgen(js_namespace = console)]
  fn log(s: &str);
}

// 调用 Javascript 的函数
#[wasm_bindgen(module = "/www/src/utils.js")]
extern "C" {
  fn now() -> usize;
  fn rnd(max: usize) -> usize;
}

#[wasm_bindgen]
pub fn greet() {
  alert(&format!("Hello, Wasm1!!! {}", now().to_string()));
  log(&format!("Hello, Wasm2!!! {}", rnd(100).to_string()));
}
